package com.anb.common;

public class CyclicCounter {
    public CyclicCounter(long min, long max) {
        this.min = min;
        this.max = max;
        this.current = min;
    }

    public CyclicCounter(long min) {
        this(min, Long.MAX_VALUE);
    }

    public CyclicCounter() {
        this(Long.MIN_VALUE);
    }

    private long min;
    private long max;
    private long current;

    public synchronized long next() {
        long value = current;
        if (current >= max) {
            current = min;
        } else {
            current += 1;
        }
        return value;
    }
}
